﻿using SharpTestsEx;
using ar.com.juanpabloibanez.MVC.PagerHelper.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ar.com.juanpabloibanez.MVC.PagerHelper.Tests
{
    /// <summary>
    ///This is a test class for MathHelperTest and is intended
    ///to contain all MathHelperTest Unit Tests
    ///</summary>
    [TestClass]
    public class MathHelperTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod]
        public void CalcLowerAndUpperBoundTest01()
        {
            const int currentPage = 7;
            const int pagesInPager = 10;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(1);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(10);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest02()
        {
            const int currentPage = 17;
            const int pagesInPager = 10;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(11);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(20);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest03()
        {
            const int currentPage = 57;
            const int pagesInPager = 10;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(51);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(57);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest04()
        {
            const int currentPage = 7;
            const int pagesInPager = 5;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(6);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(10);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest05()
        {
            const int currentPage = 17;
            const int pagesInPager = 5;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(16);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(20);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest06()
        {
            const int currentPage = 3;
            const int pagesInPager = 5;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(1);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(5);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest07()
        {
            const int currentPage = 57;
            const int pagesInPager = 5;
            const int totalPages = 57;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(56);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(57);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest08()
        {
            const int currentPage = 10;
            const int pagesInPager = 10;
            const int totalPages = 10;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(1);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(10);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest09()
        {
            const int currentPage = 90;
            const int pagesInPager = 10;
            const int totalPages = 100;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(81);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(90);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest10()
        {
            const int currentPage = 90;
            const int pagesInPager = 5;
            const int totalPages = 100;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(86);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(90);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest11()
        {
            const int currentPage = 11;
            const int pagesInPager = 10;
            const int totalPages = 100;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(11);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(20);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest12()
        {
            const int currentPage = 11;
            const int pagesInPager = 5;
            const int totalPages = 100;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(11);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(15);
        }

        [TestMethod]
        public void CalcLowerAndUpperBoundTest13()
        {
            const int currentPage = 1;
            const int pagesInPager = 5;
            const int totalPages = 0;

            int lowerBound = MathHelper.CalcLowerBound(currentPage, pagesInPager, totalPages);
            lowerBound.Should().Be.EqualTo(0);

            int upperBound = MathHelper.CalcUpperBound(currentPage, pagesInPager, totalPages);
            upperBound.Should().Be.EqualTo(0);
        }

        [TestMethod]
        public void CalcTotalPagesTest1()
        {
            MathHelper.CalcTotalPages(51, 10).Should().Be.EqualTo(6);
        }

        [TestMethod]
        public void CalcTotalPagesTest2()
        {
            MathHelper.CalcTotalPages(50, 10).Should().Be.EqualTo(5);
        }

        [TestMethod]
        public void CalcTotalPagesTest3()
        {
            MathHelper.CalcTotalPages(10, 10).Should().Be.EqualTo(1);
        }

        [TestMethod]
        public void CalcTotalPagesTest4()
        {
            MathHelper.CalcTotalPages(1, 10).Should().Be.EqualTo(1);
        }

        [TestMethod]
        public void CalcTotalPagesTest5()
        {
            MathHelper.CalcTotalPages(0, 10).Should().Be.EqualTo(0);
        }

        [TestMethod]
        public void CalcFirstItemTest01()
        {
            MathHelper.CalcFirstItem(8, 10, 100).Should().Be.EqualTo(71);
        }

        [TestMethod]
        public void CalcFirstItemTest02()
        {
            MathHelper.CalcFirstItem(1, 10, 100).Should().Be.EqualTo(1);
        }

        [TestMethod]
        public void CalcFirstItemTest03()
        {
            MathHelper.CalcFirstItem(1, 10, 0).Should().Be.EqualTo(0);
        }

        [TestMethod]
        public void CalcLastItemTest01()
        {
            MathHelper.CalcLastItem(8, 10, 100).Should().Be.EqualTo(80);
        }

        [TestMethod]
        public void CalcLastItemTest02()
        {
            MathHelper.CalcLastItem(1, 10, 5).Should().Be.EqualTo(5);
        }

        [TestMethod]
        public void CalcLastItemTest03()
        {
            MathHelper.CalcLastItem(1, 10, 0).Should().Be.EqualTo(0);
        }

        [TestMethod]
        public void CalcNextPageTest01()
        {
            MathHelper.CalcNextPage(5, 100).Should().Be.EqualTo(6);
        }

        [TestMethod]
        public void CalcNextPageTest02()
        {
            MathHelper.CalcNextPage(100, 100).Should().Be.EqualTo(100);
        }

        [TestMethod]
        public void CalcPreviousPageTest01()
        {
            MathHelper.CalcPreviousPage(5).Should().Be.EqualTo(4);
        }

        [TestMethod]
        public void CalcPreviousPageTest02()
        {
            MathHelper.CalcPreviousPage(1).Should().Be.EqualTo(1);
        }
    }
}
